package com.summer.sign.controller;

import java.util.HashMap;
import java.util.Map;
import java.util.Random;

import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;

import com.alibaba.fastjson.JSONObject;
import com.summer.core.annotations.ScopeType;
import com.summer.core.util.FacesUtil;
import com.summer.dingding.util.DingDingUtil;

@Scope(ScopeType.VIEW)
@Component
public class ManualSignHome {
	
	private String userId;
	
	private String type;
	private String token;
	private String address = "长春品高";
	private String lon;
	private String lat;
	private String signType = "1";

//	public static void main(String[] args) {
//		DingDingUtil.
//	}
	// xia
	//857d6932-2b17-42c1-8d0e-b5706da715c8
//	Bearer 857d6932-2b17-42c1-8d0e-b5706da715c8
//	lat:43.837323974584379
//	lon:125.2952230258887
	
	public void manualSign() throws Exception {
		String url = "";
		if(getType() == null || getType().equalsIgnoreCase("")) {
			FacesUtil.addErrorMessage("选个打卡方式再打卡");
			return;
		}
		String type = getType();
		
		JSONObject json = null;
		if(type.equals("app")) {
			FacesUtil.addErrorMessage("app不让用了");
			return;
////			url = "http://okr-prod.bingocloudos.net/attapi/attendance/attRecord/singn/update";
//			url = "http://localhost:8080/api/v1/parts/sign/noauth";
//			Map<String, String> headers = new HashMap<>();
//			headers.put("Authorization", "Bearer " + this.token);
//			headers.put("X-APP-ID", "010001");
//			headers.put("User-Agent", "APP/0.0.22(iPhone;iOS 15.1;Scale/3.00)");
//			JSONObject params = new JSONObject();
//			params.put("userId", this.userId);
//			params.put("address", this.address);
////			params.put("token", "Bearer " + this.token);
//			params.put("lon", getLon());
//			params.put("lat", getLat());
//			params.put("signType", "1");
//			String res = DingDingUtil.sendHttpPost(url, headers, params.toJSONString());
//			json = JSONObject.parseObject(res);
		} else {
			url = "http://okr-prod.bingocloudos.net/attapi/irobot/access/attendance/sign";
//			url = "http://localhost:8080/api/v1/parts/sign/noauth";
			
			Map<String, String> headers = new HashMap<>();
			headers.put("X-MACHINE-CODE", "1f43fbfdef");
			json = DingDingUtil.ossHttpGetUtil(url + "?userId=" + userId,  headers);
		}
		
		
		FacesUtil.addInfoMessage(json.toJSONString());
	}
	
	public String getUserId() {
		return userId;
	}

	public void setUserId(String userId) {
		this.userId = userId;
	}

	public String getType() {
		return type;
	}

	public void setType(String type) {
		this.type = type;
	}

	public String getToken() {
		return token;
	}

	public void setToken(String token) {
		this.token = token;
	}

	public String getLon() {
//		125.2952230258887
//		43.837323974584379
		StringBuffer lon = new StringBuffer("125.29522");
//		610394285
		Random random = new Random();
		
		for(int i = 0; i < 8; i++) {
			lon.append(random.nextInt(10));
		}
		return lon.toString();
	}

	public void setLon(String lon) {
		this.lon = lon;
	}

	public String getLat() {
//		125.2952230258887
//		43.837323974584379
		StringBuffer lat = new StringBuffer("43.837");
		Random random = new Random();
		
		for(int i = 0; i < 12; i++) {
			lat.append(random.nextInt(10));
		}
		return lat.toString();
	}

	public void setLat(String lat) {
		this.lat = lat;
	}

	public String getAddress() {
		return address;
	}

	public void setAddress(String address) {
		this.address = address;
	}

	public String getSignType() {
		return signType;
	}

	public void setSignType(String signType) {
		this.signType = signType;
	}
	
}

